package com.thunbu.thunbu_meeting_system.view.treeView;

import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.thunbu.thunbu_meeting_system.R;
import com.thunbu.thunbu_meeting_system.bean.DepartmentModel;


/**
 * Created by tlh on 2016/10/1 :)
 */

public class NodeBinder extends TreeViewBinder<NodeBinder.ViewHolder> {
    @Override
    public ViewHolder provideViewHolder(View itemView) {
        return new ViewHolder(itemView);
    }

    @Override
    public void bindView(ViewHolder holder, int position, TreeNode node) {
        holder.ivArrow.setRotation(0);
        holder.ivArrow.setImageResource(R.mipmap.ic_keyboard_arrow_right_black_18dp);
        int rotateDegree = node.isExpand() ? 90 : 0;
        holder.ivArrow.setRotation(rotateDegree);
        NodeModel nodeModel = (NodeModel) node.getContent();
        holder.tvName.setText(nodeModel.getName());
        if (node.isLeaf())
            holder.ivArrow.setVisibility(View.INVISIBLE);
        else holder.ivArrow.setVisibility(View.VISIBLE);
        if(node.getContent()!=null && node.getContent() instanceof DepartmentModel){
            boolean isUser = ((DepartmentModel) node.getContent()).isUser();
            holder.tvName.setTextColor(isUser? Color.parseColor("#408FFF"):Color.parseColor("#333333"));
        }else {
            holder.tvName.setTextColor(Color.parseColor("#333333"));
        }
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_treeview;
    }

    @Override
    public long getmId() {
        return 0;
    }

    public static class ViewHolder extends TreeViewBinder.ViewHolder {
        private ImageView ivArrow;
        private TextView tvName;

        public ViewHolder(View rootView) {
            super(rootView);
            this.ivArrow = (ImageView) rootView.findViewById(R.id.iv_arrow);
            this.tvName = (TextView) rootView.findViewById(R.id.tv_name);
        }

        public ImageView getIvArrow() {
            return ivArrow;
        }

        public TextView getTvName() {
            return tvName;
        }
    }
}
